package com.biz.primus.ms.oms.dao.po.returns;

import com.biz.primus.model.oms.enums.CancelType;
import com.biz.primus.model.oms.enums.returns.AuditState;
import com.biz.primus.model.oms.enums.returns.ReturnState;
import com.biz.primus.model.oms.vo.OmsOrderReturnVo;
import com.biz.primus.ms.base.jpa.po.BaseEntity;
import com.biz.primus.ms.oms.jpa.ReturnOriginDataWithJSONConverter;
import lombok.Data;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author yanweijin
 * @date 2017/11/9
 */
@Data
@Entity
@Table(name = "oms_return",indexes = {
		@Index(name = "idx_order_id", columnList = "orderId"),
		@Index(name = "idx_user_id", columnList = "userId"),
		@Index(name = "idx_order_code", columnList = "orderCode"),
		@Index(name = "idx_return_code", columnList = "returnCode"),
})
public class OmsReturn extends BaseEntity {

	/**
	 * 订单id
	 */
	private Long orderId;

	/**
	 * 退货单来源
	 */
	private String returnSource;

	/**
	 * 订单来源
	 */
	private  String orderSource;

	/**
	 * 用户id
	 */
	private Long userId;

	/**
	 * 订单编号
	 */
	@Column(length = 50)
	private String orderCode;

	/**
	 * 退货单编号
	 */
	@Column(length = 50)
	private String returnCode;

	/**
	 * 门店编号
	 */
	@Column(length = 50)
	private String depotCode;

	/**
	 * 退货审核状态
	 */
	@Enumerated(EnumType.STRING)
	@Column(length = 50)
	private AuditState auditState;

	/**
	 * 退货状态
	 */
	@Enumerated(EnumType.STRING)
	@Column(length = 50)
	private ReturnState returnState;

	/**
	 * 取消标识
	 */
	@Enumerated(EnumType.STRING)
	@Column(length = 50)
	private CancelType cancelType = CancelType.none;

	/**
	 * 退货单渠道
	 */
	@Column(length = 50)
	private String channel;

	/**
	 * 退货收货确认人(操作员编号)
	 */
	@Column(length = 50)
	private String receiver;

	/**
	 * 收货确认时间
	 */
	private LocalDateTime receiveTime;

	/**
	 * 是否需要退款,如果需要,则自动生成退款单
	 */
	boolean needRefund;

	/**
	 * 申请的退款金额(生成退款单时使用)
	 */
	private Integer returnAmount;

	/**
	 * 实际退款金额
	 */
	private Integer refundAmount;

	@OneToMany(mappedBy = "returns",cascade = CascadeType.ALL)
	private List<OmsReturnItem> items;

	/**
	 * 全网收单系统下,原始退单数据json
	 */
	@Column(columnDefinition = "TEXT")
	@Convert(converter = ReturnOriginDataWithJSONConverter.class)
	private OmsOrderReturnVo originData;


	/**
	 * 快递单号
	 */
	@Column(length = 50)
	private String expressNumber;

	/**
	 * 第三方物流公司
	 */
	@Column(length = 50)
	private String expectedExpressProviderText;


	/**
	 * 客户备注/退货说明
	 */
	@Column(length = 200)
	private String remark;

	/**
	 * 客服备注(用户不可见)
	 */
	@Column(length = 200)
	private String selfRemark;

}
